package com.example.transaction.transaction.dao1;

import com.example.transaction.transaction.pojp.Account;
import com.example.transaction.transaction.service1.AccountService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: AccountServiceImpl1
 * @DESCRIPT: TODO
 * @AUTHOR: lemontree
 * @DATA: 2020/7/23 9:25 PM
 **/
@Service
@Transactional(propagation = Propagation.NEVER)
public class AccountServiceImpl1 implements AccountService1 {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int update(Account account) {
        String sql = "update account set money = ? where id = ?";

        List<Object> list = new ArrayList<>();
        list.add(account.getMoney());
        list.add(account.getId());
        return jdbcTemplate.update(sql,list.toArray());
    }

    @Override
    public int delete(int id) {
        String sql = "delete from account where id = ?";
        jdbcTemplate.update(sql,id);
        return 0;
    }
}
